<%= form_for [:shop, @spu, @sku], html: { class: "card" } do |f| %>
  <div class="card-body">
    <h3 class="card-title">
      <%= @sku.new_record? ? "新增" : "修改" %>属性
    </h3>
    <div class="row">
      <%= render 'shop/shared/error_messages', target: @sku %>
    </div>
    <div class="row">
      <div class="col-md-4">
        <div class="form-group">
          <label class="form-label">编码</label>
          <%= f.text_field :name, class: "form-control" %>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-group">
          <label class="form-label">展示图片</label>
          <div class="custom-file">
            <%= f.file_field :avatar, class: "custom-file-input" %>
            <label class="custom-file-label">选择文件</label>
          </div>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-group">
          <label class="form-label">库存</label>
          <%= f.number_field :on_hand_count, class: "form-control" %>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-group">
          <label class="form-label">成本价</label>
          <%= f.number_field :cost_price, class: "form-control", step: "0.01" %>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-group">
          <label class="form-label">销售价</label>
          <%= f.number_field :sale_price, class: "form-control", step: "0.01" %>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-group">
          <label class="form-label">
            促销价
            <small>商品促销可用，清仓<
            <% if not @sku.new_record? %>
              <%= (@sku.sale_price - @sku.cost_price) / 2 + @sku.cost_price %>
            <% end %>
            元</small>
          </label>
          <%= f.number_field :promotion_price, class: "form-control", step: "0.01" %>
        </div>
      </div>

      <% @spu.shop_category.parent.option_types.each do |option_type| %>
        <div class="col-md-12">
          <div class="form-group">
            <label class="form-label"><%= option_type.name %></label>
            <div class="selectgroup selectgroup-pills">
              <% option_type.option_values.each_with_index do |option_value, index| %>
                <%= hidden_field_tag "sku_option_values[#{option_type.id}][option_type_id]", option_type.id %>
                <label class="selectgroup-item">
                  <%= radio_button_tag "sku_option_values[#{option_type.id}][option_value_id]", option_value.id, (@sku.option_value_selected?(option_type.id, option_value.id) unless @sku.new_record?), { class: "selectgroup-input" } %>
                  <span class="selectgroup-button">
                    <%= option_value.presentation %>
                  </span>
                </label>
              <% end %>
            </div>
          </div>
        </div>
      <% end %>
      
    </div>
  </div>
  <div class="card-footer text-right">
    <%= f.submit "保 存", class: "btn btn-primary" %>
  </div>
<% end %>